package com.lnkj.spcj.widget.helper

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import com.lnkj.spcj.R
import com.lnkj.spcj.base.CustomPicturePreviewActivity
import com.lnkj.spcj.util.ImageLoader
import com.luck.picture.lib.entity.LocalMedia
import org.jetbrains.anko.layoutInflater
import java.io.Serializable

/**
 * Copyright (c) 山东六牛网络科技有限公司 https://liuniukeji.com
 *
 * @Description
 * @Author         与天同行的观测者
 * @Copyright      Copyright (c) 山东六牛网络科技有限公司 保留所有版权(https://www.liuniukeji.com)
 * @Date           $date$ $time$
 */
class NineGridViewAdapter(var mContext: Context, var mutableList: MutableList<LocalMedia>) : BaseAdapter() {
    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var view = mContext.layoutInflater.inflate(R.layout.item_nine_gridview, null)
        var iv = view.findViewById<ImageView>(R.id.iv)
        ImageLoader.loadImage(mContext, iv, getItem(p0).path)
        view.setOnClickListener {
            val intent = Intent(mContext, CustomPicturePreviewActivity::class.java)
            intent.putExtra("previewSelectList", mutableList as Serializable)
            intent.putExtra("position", p0)
            mContext.startActivity(intent)
            (mContext as Activity).overridePendingTransition(R.anim.a5, 0)
//            PictureSelector.create(context as Activity).themeStyle(R.style.picture_default_style).openExternalPreview(p0, mutableList)
        }
        return view
    }

    override fun getItem(p0: Int): LocalMedia {
        return mutableList[p0]
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        return mutableList.size
    }
}